<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <link rel="stylesheet" href="static/elementui.css">
    <title>Title</title>
    <style>
        .demo-ruleForm{
            width: 400px;
        }
    </style>
</head>
<body>
<div id="app">
    <el-form :model="ruleForm" :rules="rules" ref="ruleForm" label-width="100px" class="demo-ruleForm">
        <el-form-item label="名称" prop="username">
            <el-input v-model="ruleForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="pwd">
            <el-input v-model="ruleForm.pwd"></el-input>
        </el-form-item>
        <el-form-item label="记住密码" prop="rem">
            <el-switch v-model="ruleForm.rem"></el-switch>
        </el-form-item>
        <el-form-item>
            <el-button type="primary" @click="submitForm('ruleForm')">立即创建</el-button>
        </el-form-item>
    </el-form>
</div>

<script src="static/vue.js"></script>
<script src="static/element.js"></script>
<script src="static/axios.js"></script>
<script>
    var vm=new Vue({
        el:"#app",
        data() {
            return {
                ruleForm: {
                    username: '',
                    pwd: '',
                    actionName: 'login',
                    rem: true,
                },
                rules: {
                    name: [
                        { required: true, message: '请输入名称', trigger: 'blur' },
                        { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
                    ],
                    pwd: [
                        { required: true, message: '请输入密码', trigger: 'blur' },
                        { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
                    ],

                }
            };
        },
        methods: {
            submitForm(formName) {
                var that=this
                this.$refs[formName].validate((valid) => {
                    if (valid) {
                        axios({
                            headers: {
                                'Content-Type': 'application/x-www-form-urlencoded'
                            },
                            method: 'post',
                            url: '/user',
                            params: {
                                username: that.ruleForm.username,
                                pwd: that.ruleForm.pwd,
                                rem: that.ruleForm.rem?"1":"0",
                                actionName: that.ruleForm.actionName,
                            }
                        }).then(function(response){

                        }).catch(function (response){

                        });
                    } else {
                        console.log('error submit!!');
                        return false;
                    }
                });
            },
            resetForm(formName) {
                this.$refs[formName].resetFields();
            }
        }
    })
</script>
</body>
</html>
